require([], function () {
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [107.49023438, 36.24427318],
        zoom: 4
    });
    var marker;

    function createMaker(lgt, ltt) {
        if (!marker) {
            marker = new AMap.Marker({
                icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
                draggable: true,
                cursor: 'move',
                position: [lgt, ltt]
            });
            marker.setMap(map);
            AMap.event.addListener(marker, 'dragend', function () {
                document.getElementById("lnglat").value = marker.getPosition().getLng() + ',' + marker.getPosition().getLat();
            });
        } else {
            marker.setPosition(new AMap.LngLat(lgt, ltt));
        }
    }

    //为地图注册click事件获取鼠标点击出的经纬度坐标
    map.on('click', function (e) {
        document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat();
        createMaker(e.lnglat.getLng(), e.lnglat.getLat());
    });

    window.setLgtLtt = function (postion) {
        if (postion && postion.trim()) {
            var lgtLtt = postion.split(',');
            if (lgtLtt.length == 2) {
                createMaker(lgtLtt[0], lgtLtt[1]);
                $("#lnglat").val(lgtLtt[0] + ',' + lgtLtt[1]);
                map.setCenter([lgtLtt[0], lgtLtt[1]]);
            }
        }
    };

    window.getLgtLtt = function () {
        return $("#lnglat").val();
    }

});